主题
生成鼠标渐开线随机移动轨迹 - GenerateInvoluteMouseTrajectory
函数简介
在指定半径范围内生成渐开线式随机游走轨迹,模拟自然的鼠标移动。
返回数据格式:
json
[{"x": 100, "y": 200}, ...]| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | 轨迹点的 X 坐标。 |
| y | 整数 | 轨迹点的 Y 坐标。 |
接口名称
GenerateInvoluteMouseTrajectoryDLL调用
c
long GenerateInvoluteMouseTrajectory(long ola, int startX, int startY, int radius, int stepDistance, double curvature, double noiseAmplitude);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| startX | 整数型 | 起点X坐标(中心点)。 |
| startY | 整数型 | 起点Y坐标(中心点)。 |
| radius | 整数型 | 移动半径范围(像素)。 |
| stepDistance | 整数型 | 轨迹点之间的距离(像素,建议3-10,0表示自动计算为5)。 |
| curvature | 双精度浮点数 | 曲率系数(0.5-2.0,越大越弯曲,默认1.0)。 |
| noiseAmplitude | 双精度浮点数 | 随机扰动幅度(0-5像素,默认2.0)。 |
参数详细说明
stepDistance(步距):
- 精细模式:3-5像素,轨迹平滑但点数多。
- 标准模式:5-8像素,平衡性能和效果。
- 快速模式:8-10像素,点数少但可能不够平滑。
- 传入0时自动使用默认值5像素。
curvature(曲率系数):
- 0.5:轻微弯曲,接近直线。
- 1.0:标准弯曲(推荐)。
- 1.5-2.0:高度弯曲,更自然随机。
noiseAmplitude(扰动幅度):
- 0-1.0:轻微抖动。
- 1.0-3.0:标准抖动,模拟人手(推荐)。
- 3.0-5.0:明显抖动。
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
auto result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
var result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
var result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0);cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0)text
.局部变量 ola, OLAPlug
ola.创建 ()
result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
自动 result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
auto result = ola.GenerateInvoluteMouseTrajectory(0, 0, 0, 0, 1.0, 1.0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = GenerateInvoluteMouseTrajectory(instance, 0, 0, 0, 0, 1.0, 1.0);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long GenerateInvoluteMouseTrajectory(long ola, int startX, int startY, int radius, int stepDistance, int curvature, int noiseAmplitude);
long instance = CreateCOLAPlugInterFace();
long ptr = GenerateInvoluteMouseTrajectory(instance, 0, 0, 0, 0, 1.0, 1.0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.GenerateInvoluteMouseTrajectory(instance, 0, 0, 0, 0, 1.0, 1.0)
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
字符串指针地址,包含JSON格式的轨迹点数组数据。返回 0 表示失败。
注意事项
- DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
